package com.j2110.dao;

import com.j2110.pojo.Dept;
import com.j2110.pojo.Emp;
import com.j2110.utils.DSUtil;

import java.util.List;

public class DeptDao {

    //查询所有
    public List<Dept> query(){
        return DSUtil.query("select * from dept", Dept.class );
    }

    //添加数据
    public int execute(Dept dept) {
        return DSUtil.execute("insert into dept values(null,?,?,?,?)", dept.getName(),dept.getManager(),dept.getTel(),dept.getNum());
    }

    //删除数据
    public int delete(String id) {
        return DSUtil.execute("delete from dept where id = ?", id);
    }

    public int update(Dept dept) {
        return DSUtil.execute("update dept set name = ?,manager = ?,tel = ?,num = ? where id = ?",
                dept.getName(),dept.getManager(),dept.getTel(),dept.getNum(),dept.getId());
    }

    public List<Dept> queryById(String id) {
        return DSUtil.query("select * from dept where id = ?",Dept.class,id);
    }

    public List<Dept> queryByName(String name) {
        return DSUtil.query("select * from dept where name = ?",Dept.class,name);
    }
}
